import java.util.ArrayList;
import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: mirac
 * Date: 2025-08-01
 * Time: 18:47
 */
public class Solution {
    public List<List<Integer>> generate(int numRows) {
        List<List<Integer>> lists = new ArrayList<>();
        List<Integer> list0 = new ArrayList<>();
        list0.add(1);
        lists.add(list0);

        for (int i = 1; i < numRows; i++) {
            List<Integer> curRow = new ArrayList<>();
            //处理第一个元素
            curRow.add(1);

            //中间的元素
            //获取上一行
            List<Integer> preRow = lists.get(i-1);
            for (int j = 1; j < i; j++) {
                int value1 = preRow.get(j);
                int value2 = preRow.get(j - 1);
                curRow.add(value1 + value2);
            }
            //处理最后一个元素
            curRow.add(1);

            //将这一行放到顺序表中
            lists.add(curRow);
        }
        return lists;
    }
}
